<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');

/*
 * MEDIA
 */

$GLOBALS['TL_DCA']['tl_module']['fields']['media_headline'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_module']['media_headline'],
	'exclude'                 => true,
	'inputType'               => 'text',
		'eval'                    => array('tl_class'=>'w50'),
);

$GLOBALS['TL_DCA']['tl_module']['fields']['media_description'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_module']['media_description'],
	'exclude'                 => true,
	'inputType'               => 'text',
	'eval'                    => array('tl_class'=>'w50'),
		
);
$GLOBALS['TL_DCA']['tl_module']['fields']['media_width'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_module']['media_width'],
	'exclude'                 => true,
	'default'				  => 263,
	'inputType'               => 'text',
	'eval'                    => array('mandatory'=>true,'tl_class'=>'w50'),
	
);

$GLOBALS['TL_DCA']['tl_module']['fields']['media_height'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_module']['media_height'],
	'exclude'                 => true,
	'default'				  => 168,
	'inputType'               => 'text',
	'eval'                    => array('mandatory'=>true,'tl_class'=>'w50')
		
);
$GLOBALS['TL_DCA']['tl_module']['fields']['typeurl'] = array
		(
			'label'                   => &$GLOBALS['TL_LANG']['tl_module']['media_type_url'],
			'filter'                  => true,
			'inputType'               => 'radio',
			'options'		  => array('media_link','media_linkurl'),
			'eval'                    => array('submitOnChange'=>true,)
			
		);
$GLOBALS['TL_DCA']['tl_module']['fields']['media_link'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_module']['media_link'],
	'inputType'               	=> 'fileTree',
	'eval'                    	=> array('fieldType'=>'radio', 'files'=>true, 'filesOnly'=>true, 'class'=>'mandatory'),
	
);

$GLOBALS['TL_DCA']['tl_module']['fields']['media_linkurl'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_module']['media_linkurl'],
	'inputType'               => 'text',

);

$GLOBALS['TL_DCA']['tl_module']['fields']['media_image'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_module']['media_image'],
	'inputType'               => 'text',

);
$GLOBALS['TL_DCA']['tl_module']['fields']['media_autostart'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_module']['media_autostart'],
	'inputType'               	=> 'checkbox',
	'eval'                    => array('submitOnChange'=>true),
	
);
$GLOBALS['TL_DCA']['tl_module']['palettes']['teaser_media'] = '{title_media_legend},name;{title_headline},media_headline;{width_height_legend},media_width,media_height;{title_linkurl},media_link;{title_image},media_image';

// $GLOBALS['TL_DCA']['tl_module']['palettes']['teaser_media'] = '{title_media_legend},name;{title_headline},media_headline,media_description;{width_height_legend},media_width,media_height;{title_linkurl},media_linkurl,media_link;{title_image},media_image;media_autostart';


/*
 * CLASS CALLBACK
 */
class tt_media extends Backend
{
	public function getMedia()
	{
		$strQuery = "select media_id, media_link from tl_module";
		$objResult = $this->Database->execute($strQuery);

		if($objResult->numRows < 1) {
			return array();
		}

		$arrResult = array();

		if (TL_MODE == 'BE')
		{
			while ($objResult->next())
			{
				$strLink = $this->getLink($objResult->media_id);
				$arrResult[$objResult->id] = $strLink;
			}
			
			return $arrResult;
		}

		return $arrResult;
	}

    private function getLink($id)
    {
    	$strQuery = "select media_link from tl_module where id = ?";
    	$objResult = $this->Database->prepare($strQuery)->execute($id);
    	
    	if($objResult < 1)
    		return '';
    	else	
    		return $strName = $objResult->media_link;
    }
     private function autoStart($id)
    {
    	$strQuery = "select autoStart from tl_module where id = ?";
    	$objResult = $this->Database->prepare($strQuery)->execute($id);
    	
    	if($objResult < 1)
    		return '';
    	else	
    		return $strName = $objResult->media_link;
    }

	public function getChoice()
	{
		return array('1' => 'Source Video', '2' => 'Url Video');
		}
    
}

?>